package com.jwthhealth_pub.old.sportfitness.view.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.common.ImageLoader;
import com.jwthhealth_pub.old.sportfitness.module.SportHomeModule;
import com.jwthhealth_pub.old.sportfitness.view.SportFitnessHomeActivity;
import com.jwthhealth_pub.old.sportfitness.view.SportfitnessCourseListActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/1/4.
 */
public class SportFitnessHomeAdapter extends RecyclerView.Adapter {

    private SportFitnessHomeActivity activity;
    private List<SportHomeModule.DataBean> list;

    public SportFitnessHomeAdapter(SportFitnessHomeActivity sportFitnessActivity, List<SportHomeModule.DataBean> module) {
        this.activity = sportFitnessActivity;
        this.list = module;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(activity, R.layout.item_sportfitness, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;

        final SportHomeModule.DataBean dataBean = list.get(position);
        viewHolder.text.setText(dataBean.getName());
//        Picasso.with(activity).load(dataBean.getPic_path()).into(viewHolder.img);
        ImageLoader.picasso(dataBean.getPic_path(), viewHolder.img);

        viewHolder.clickLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(activity, SportfitnessCourseListActivity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable(Constant.SPORT_DATA, dataBean);
                intent.putExtras(bundle);
                activity.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder{

        RelativeLayout clickLayout;
        TextView text;
        ImageView img;

        public ViewHolder(View itemView) {
            super(itemView);
            clickLayout = (RelativeLayout) itemView.findViewById(R.id.click_layout);
            img = (ImageView) itemView.findViewById(R.id.img);
            text = (TextView) itemView.findViewById(R.id.text);
        }
    }
}
